package com.imooc.security.data.pojo.utils;

import com.imooc.security.data.pojo.exception.CommonException;
import com.imooc.security.data.pojo.exception.CommonResponseEnum;
import com.imooc.security.data.pojo.response.CommonResponseDto;

/**
 * Response util.
 *
 * @author Created By Houce
 */
public final class ResponseUtil {

    /**
     * private constructor.
     */
    private ResponseUtil() {

    }

    /**
     * Wrap null response body of success.
     *
     * @return ResponseDto
     */
    public static CommonResponseDto wrapSuccess() {

        return new CommonResponseDto(CommonResponseEnum.SUCCESS);
    }

    /**
     * Wrap response body of success.
     *
     * @param body returned object
     * @return ResponseDto
     */
    public static CommonResponseDto wrapSuccess(final Object body) {

        return new CommonResponseDto(CommonResponseEnum.SUCCESS, body);
    }


    public static CommonResponseDto wrapExceptionLog(final String message,final Object body) {
        final String code = "40000";
        return new CommonResponseDto(code,message,body);
    }

    /**
     * @param code error code
     * @param message error message
     * @return ResponseDto
     */
    public static CommonResponseDto wrapException(final String code, final String message) {

        return new CommonResponseDto(code, message);
    }

    /**
     * @param e ApplicationException
     * @return ResponseDto
     */
    public static CommonResponseDto wrapException(final CommonException e) {

        return new CommonResponseDto(e);
    }


    public static CommonResponseDto wrapException(final String code, final String message,final Object body) {

        return new CommonResponseDto(code, message,body);
  }
}